home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
YERK
/
SUPPLEME
/
UNSUPPOR
/
OPTIONAL
/
DICTIONA.RY
< prev
next >
Wrap
Text File
|
1986-01-08
|
4KB
|
143 lines
\ DICTIONARY CLASS Reese Warner 4/85
\ Useful for symbol tables, et. al.
1 -> dlevel
:CLASS DictElt <super String
Var Ptr \ pointer to the next element in the collision
\ resolution chain
Var Info \ contains the data associated with the word
:M PUTDATA: put: info ;M
:M GETDATA: get: info ;M
:M SETNEXT: put: ptr ;M
:M GETNEXT: get: ptr ;M
:M DISPOSE:
getNext: self 0= not
IF
dispose: [ getNext: self ]
dispose: ptr
THEN ;M
;CLASS
:CLASS Dictionary <super Array
\ CHAIN - does the main work of methods ENTER & QUERY. Intended to be a private
\ method for class DICTIONARY. Searchs the chain at a given bucket for
\ string. If String not found then returns false, otherwise true. Objaddr
\ points to last element in chain.
:M CHAIN: { objAddr strObj \ oldAddr flag -- objAddr bool }
FALSE -> flag
BEGIN
get: strObj get: objAddr s=
IF
TRUE -> flag
THEN
objAddr -> oldAddr
getnext: objAddr -> objAddr
objAddr 0= flag or
UNTIL
oldAddr flag
;M
\ QUERY - returns value associated with String in dictionary. If string is
\ not found in dictionary, then 0 is returned.
:M QUERY: { strObj \ idx checkAddr val -- val }
get: strObj str255 -base hash limit: self mod -> idx
idx at: self -> checkAddr
checkAddr 0=
IF
0 -> Val
ELSE
checkAddr strObj chain: self swap -> checkAddr
IF
getData: checkAddr -> val
ELSE
0 -> val
THEN
THEN
val
;M
\ ENTER - puts the string and value into the dictionary. If the string is
\ already in the dictionary then it changes the value to the new value.
:M ENTER: { val strObj \ idx EltAddr OldAddr -- }
get: strObj str255 -base hash limit: super mod -> idx
idx at: super -> oldAddr
oldAddr 0=
IF
Heap> DictElt -> EltAddr new: EltAddr
get: strObj put: EltAddr
val putData: EltAddr
EltAddr idx to: super
ELSE
oldAddr strObj chain: self swap -> oldAddr
IF
val putData: oldAddr
ELSE
heap> DictElt -> EltAddr new: EltAddr
get: strObj put: EltAddr
val putData: EltAddr
EltAddr setNext: oldAddr
THEN
THEN
;M
\ EXEC - for every element in the dictionary exec: executes routine with the
\ associated value and an addr/len pair representing the hashed string as
\ an argument
:M EXEC: { routine \ objAddr -- }
limit: self 0
DO
i at: self -> objAddr
objAddr 0= not
IF
BEGIN
getData: objAddr get: objAddr exec> routine
getNext: objAddr -> objAddr
objAddr 0=
UNTIL
THEN
LOOP
;M
:M DISPOSE:
limit: super 0
DO
i at: super 0= not
IF
dispose: [ i at: super ]
i dispose: super
THEN
LOOP
;M
;CLASS
:CLASS Symbols <SUPER Dictionary
\ QUERY - returns value associated with String in dictionary and FoundFlag. If
\ string is not found in dictionary, then 0 0 is returned. Needed for SymTab
\ where 0 is valid value.
:M QUERY: { strObj \ idx checkAddr val found -- val found }
FALSE -> Found
get: strObj str255 -base hash limit: self mod -> idx
idx at: self -> checkAddr
checkAddr
IF
checkAddr strObj chain: self -> Found -> checkAddr
Found
IF
getData: checkAddr -> val
THEN
THEN
val Found
;M
;CLASS